home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DLLCust_Files / FUNCTION / DECAYSIN.C next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.6 KB  |  51 lines

  1. // Dynamic link library implementation of NeuroSolutions Function component for Sine setting
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /***************************/
  6. /* Activation of component */
  7. __declspec(dllexport) NSFloat performFunction(
  8.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  9.     NSFloat    x         // Current argument in radians
  10.     )
  11. {
  12.     int cycles = getIntParameter(instance, 3, 1);
  13.     NSFloat decay = getFloatParameter(instance, 2, 1);
  14.     NSFloat *amplitudeDecay = getUserData(instance);
  15.     NSFloat function = (NSFloat)(*amplitudeDecay*sin(cycles*x));
  16.     *amplitudeDecay *= decay;
  17.     return function;
  18. }
  19.  
  20. /**********************************************************************/
  21. /* Called before any performFunction calls, allowing any initialization. */
  22. __declspec(dllexport) void getReadyToFire(
  23.     DLLData    *instance    // Pointer to instance data (may be NULL) 
  24.     )
  25. {
  26.     NSFloat *amplitudeDecay = getUserData(instance);
  27.     *amplitudeDecay = 1.0f;
  28. }
  29.  
  30. /******************************************/
  31. /* Management of instance data (OPTIONAL) */
  32. __declspec(dllexport) DLLData *allocFunction(
  33.     DLLData    *oldInstance    // Pointer to the last instance if reallocating 
  34.     ) 
  35. {
  36.     DLLData *instance = allocDLLInstance(oldInstance);
  37.     setParameterName(instance, 3, 1, "Cycles", FALSE);
  38.     setIntParameter(instance, 3, 1, 5, FALSE);
  39.     setParameterName(instance, 2, 1, "Decay", FALSE);
  40.     setFloatParameter(instance, 2, 1, 0.9f, FALSE);
  41.     setUserData(instance, malloc(sizeof(NSFloat)));
  42.     return instance;
  43. }
  44.  
  45. __declspec(dllexport) void freeFunction(DLLData *instance)
  46. {
  47.     if (getUserData(instance))
  48.         free((NSFloat*)getUserData(instance));
  49.     freeDLLInstance(instance);
  50. }
  51.